package com.zhoug.permission;

import android.Manifest;
import android.os.Build;

/**
 * @Author 35574
 * @Date 2021/6/8
 * @Description
 */
public class Permission {
    /****日历*/
    public static final String READ_CALENDAR = Manifest.permission.READ_CALENDAR;
    public static final String WRITE_CALENDAR = Manifest.permission.WRITE_CALENDAR;
    /****相机*/
    public static final String CAMERA = Manifest.permission.CAMERA;

    /****通讯录*/
    public static final String READ_CONTACTS = Manifest.permission.READ_CONTACTS;
    public static final String WRITE_CONTACTS = Manifest.permission.WRITE_CONTACTS;
    public static final String GET_ACCOUNTS = Manifest.permission.GET_ACCOUNTS;
    /****位置信息*/
    public static final String ACCESS_FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
    public static final String ACCESS_COARSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
    /****麦克风*/
    public static final String RECORD_AUDIO = Manifest.permission.RECORD_AUDIO;
    /****传感器*/
    public static final String BODY_SENSORS = Manifest.permission.BODY_SENSORS;
    /****存储空间*/
    public static final String READ_EXTERNAL_STORAGE = Manifest.permission.READ_EXTERNAL_STORAGE;
    public static final String WRITE_EXTERNAL_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE;
    /****短信*/
    public static final String SEND_SMS = Manifest.permission.SEND_SMS;
    public static final String READ_SMS = Manifest.permission.READ_SMS;
    public static final String RECEIVE_SMS = Manifest.permission.RECEIVE_SMS;
    public static final String RECEIVE_WAP_PUSH = Manifest.permission.RECEIVE_WAP_PUSH;
    public static final String RECEIVE_MMS = Manifest.permission.RECEIVE_MMS;
    /****电话*/
    public static final String READ_PHONE_STATE = Manifest.permission.READ_PHONE_STATE;
    public static final String CALL_PHONE = Manifest.permission.CALL_PHONE;

    public static final String ADD_VOICEMAIL = Manifest.permission.ADD_VOICEMAIL;
    public static final String USE_SIP = Manifest.permission.USE_SIP;
    public static final String PROCESS_OUTGOING_CALLS = Manifest.permission.PROCESS_OUTGOING_CALLS;
    /***通话记录*/
    public static final String READ_CALL_LOG = Manifest.permission.READ_CALL_LOG;
    public static final String WRITE_CALL_LOG = Manifest.permission.WRITE_CALL_LOG;


    /**
     * 权限分组
     */
    public static class Group {
        public static final String CALENDAR = Manifest.permission_group.CALENDAR;
        public static final String CALL_LOG = Manifest.permission_group.CALL_LOG;
        public static final String CAMERA = Manifest.permission_group.CAMERA;
        public static final String CONTACTS = Manifest.permission_group.CONTACTS;
        public static final String LOCATION = Manifest.permission_group.LOCATION;
        public static final String MICROPHONE = Manifest.permission_group.MICROPHONE;
        public static final String PHONE = Manifest.permission_group.PHONE;
        public static final String SENSORS = Manifest.permission_group.SENSORS;
        public static final String SMS = Manifest.permission_group.SMS;
        public static final String STORAGE = Manifest.permission_group.STORAGE;
    }


    public static String getGroupName(String permission) {
        String name = null;
        if (permission != null) {
            if (permission.equalsIgnoreCase(Manifest.permission.READ_CALENDAR)
                    || permission.equalsIgnoreCase(Manifest.permission.WRITE_CALENDAR)) {
                name = "日历";
            } else if (permission.equalsIgnoreCase(Manifest.permission.CAMERA)) {
                name = "相机";
            } else if (permission.equalsIgnoreCase(Manifest.permission.READ_CONTACTS)
                    || permission.equalsIgnoreCase(Manifest.permission.WRITE_CONTACTS)
                    || permission.equalsIgnoreCase(Manifest.permission.GET_ACCOUNTS)) {
                name = "通讯录";
            } else if (permission.equalsIgnoreCase(Manifest.permission.ACCESS_FINE_LOCATION)
                    || permission.equalsIgnoreCase(Manifest.permission.ACCESS_COARSE_LOCATION)) {
                name = "位置信息";
            } else if (permission.equalsIgnoreCase(Manifest.permission.RECORD_AUDIO)) {
                name = "麦克风";
            } else if (permission.equalsIgnoreCase(Manifest.permission.BODY_SENSORS)) {
                name = "传感器";
            } else if (permission.equalsIgnoreCase(Manifest.permission.READ_EXTERNAL_STORAGE)
                    || permission.equalsIgnoreCase(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                name = "存储空间";
            } else if (permission.equalsIgnoreCase(Manifest.permission.SEND_SMS)
                    || permission.equalsIgnoreCase(Manifest.permission.RECEIVE_SMS)
                    || permission.equalsIgnoreCase(Manifest.permission.READ_SMS)
                    || permission.equalsIgnoreCase(Manifest.permission.RECEIVE_MMS)
                    || permission.equalsIgnoreCase(Manifest.permission.RECEIVE_WAP_PUSH)) {
                name = "信息";
            } else {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                    if (permission.equalsIgnoreCase(Manifest.permission.READ_PHONE_STATE)
                            || permission.equalsIgnoreCase(Manifest.permission.CALL_PHONE)
                            || permission.equalsIgnoreCase(Manifest.permission.ADD_VOICEMAIL)
                            || permission.equalsIgnoreCase(Manifest.permission.USE_SIP)
                            || permission.equalsIgnoreCase(Manifest.permission.PROCESS_OUTGOING_CALLS)) {
                        name = "电话";
                    } else if (permission.equalsIgnoreCase(Manifest.permission.READ_CALL_LOG)
                            || permission.equalsIgnoreCase(Manifest.permission.WRITE_CALL_LOG)) {
                        name = "通话记录";
                    }
                } else {
                    if (permission.equalsIgnoreCase(Manifest.permission.READ_PHONE_STATE)
                            || permission.equalsIgnoreCase(Manifest.permission.CALL_PHONE)
                            || permission.equalsIgnoreCase(Manifest.permission.ADD_VOICEMAIL)
                            || permission.equalsIgnoreCase(Manifest.permission.USE_SIP)
                            || permission.equalsIgnoreCase(Manifest.permission.PROCESS_OUTGOING_CALLS)
                            || permission.equalsIgnoreCase(Manifest.permission.READ_CALL_LOG)
                            || permission.equalsIgnoreCase(Manifest.permission.WRITE_CALL_LOG)) {
                        name = "电话";
                    }
                }
            }
        }
        return name;
    }


}
